/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package popups;

/**
 *
 * @author icdev
 */
import PCR.MainFrame;
import components.*;
import java.awt.Image;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.table.DefaultTableModel;

public class ToolActionCommander extends MouseAdapter {
    
    Integer[] pos = {300,200,100};
    int count=0;

    DefaultTableModel markersModel;
    DefaultTableModel bandsModel;
    JButton b ;
    public void setMarkersModel(DefaultTableModel dtm) {
        markersModel = dtm;
    }

    public void setBandsModel(DefaultTableModel dtm) {
        bandsModel = dtm;
    }
    String toolTitle;

    public void setToolTitle(String str) {
        toolTitle = str;
    }

    @Override
    public void mouseClicked(MouseEvent e) {
        try {
            if (e.getClickCount() == 2) {
                JButton curBtn = (JButton) e.getSource();
                if (toolTitle.equals("Markers")) {
                    MarkerAction(curBtn);
                } else if (toolTitle.equals("Bands")) {
                    BandAction(curBtn);
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    /// Write here Any aCtions 
    private void BandAction(JButton PressedBtn) {
        //System.out.println(bandsModel.getValueAt(Integer.parseInt(PressedBtn.getAccessibleContext().getAccessibleDescription()), 1));
        String image = (String)bandsModel.getValueAt(Integer.parseInt(PressedBtn.getAccessibleContext().getAccessibleDescription()), 1);
        MainFrame frm = (MainFrame)java.awt.Window.getWindows()[0]; 
        BandShape band = new BandShape();
        Icon icn = new javax.swing.ImageIcon("resources/bands/"+image);
        Image img = ((ImageIcon) icn).getImage();                
        ImageIcon icon = new ImageIcon(img.getScaledInstance(120, 25, Image.SCALE_AREA_AVERAGING));
        band.setImage(icon);
        band.setSize(120,25);
        band.setVisible(true);
        band.setLocation(frm.get16Position()[3], 300);
        frm.getPCR().getWorkArea().getBandsPanel().add(band);
        frm.getPCR().getWorkArea().getBandsPanel().repaint();
        frm.setSelectedShape(band);
    }

    private void MarkerAction(JButton PressedBtn) {
        System.out.println(markersModel.getValueAt(Integer.parseInt(PressedBtn.getAccessibleContext().getAccessibleDescription()), 1));
    }
}
